import elu.base.model as model
from sqlalchemy.sql import text


class TopicModel:
    def __init__(self):
        self.engine = model.engine
        self.meta = model.meta

    def c(self):
        pass

    def u(self):
        pass

    def r(self):
        raw = """
            SELECT
            data.*,
            (SELECT su_cha.name FROM supp_channel AS su_cha WHERE su_cha.id=data.channel_id) channel_waver,
            (SELECT su_gra.name FROM supp_personnel AS su_gra WHERE su_gra.id=data.graphic_de_id) graphic_de_waver,
            (SELECT su_fro.name FROM supp_personnel AS su_fro WHERE su_fro.id=data.frontend_de_id) frontend_de_waver
            FROM data_topic AS data WHERE data.na = 1"""
        
        result = self.engine.execute(raw)
        return [dict(row) for row in result]

    def d(self):
        pass


class TopicApplicationModel:
    def __init__(self):
        self.engine = model.engine
        self.meta = model.meta

    def c(self):
        pass

    def u(self):
        pass

    def r(self):
        raw = """
        SELECT
        rela.topic_id,
        (SELECT su_app.name FROM supp_application AS su_app WHERE su_app.id=rela.application_id) application_waver
        FROM rela_topic_application AS rela"""
        
        result = self.engine.execute(raw)
        return [dict(row) for row in result]

    def d(self):
        pass
